package com.huatai.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huatai.common.util.StringUtil;
import com.huatai.manage.entity.TbFirmManageEntity;
import com.huatai.manage.mapper.TbFirmManageMapper;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.service.TbFirmManageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 厂商管理; 服务实现类
 * </p>
 *
 * @author luoxc
 * @since 2023-03-22
 */
@Service
public class TbFirmManageServiceImpl extends ServiceImpl<TbFirmManageMapper, TbFirmManageEntity> implements TbFirmManageService {

	/**
	 * 分页获取工厂列表
	 *
	 * @param pageQuery
	 * @return
	 */
	@Override
	public Page<TbFirmManageEntity> pageList(PageQuery<TbFirmManageEntity> pageQuery) {
		Page<TbFirmManageEntity> page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
		TbFirmManageEntity data = pageQuery.getData();
		LambdaQueryWrapper<TbFirmManageEntity> wrapper = Wrappers.<TbFirmManageEntity>lambdaQuery();
		wrapper.like(StringUtil.isNotBlank(data.getFirmName()), TbFirmManageEntity::getFirmName, data.getFirmName());
		return this.page(page, wrapper);
	}

	/**
	 * 根据工厂id获取单个工厂数据
	 *
	 * @param firmId
	 * @return
	 */
	@Override
	public TbFirmManageEntity getByFirmId(String firmId) {
		LambdaQueryWrapper<TbFirmManageEntity> wrapper = Wrappers.<TbFirmManageEntity>lambdaQuery();
		wrapper.eq(TbFirmManageEntity::getFirmId, firmId);
		return this.getOne(wrapper);
	}

	/**
	 * 根据工厂id集合删除工厂信息
	 *
	 * @param firmIds
	 * @return
	 */
	@Override
	public boolean removes(List<String> firmIds) {
		if (firmIds.isEmpty()) return false;
		LambdaQueryWrapper<TbFirmManageEntity> wrapper = Wrappers.<TbFirmManageEntity>lambdaQuery();
		wrapper.in(TbFirmManageEntity::getFirmId, firmIds);
		return this.remove(wrapper);
	}

	/**
	 * 根据工厂id修改工厂信息
	 *
	 * @param tbFirmManageEntity
	 * @return
	 */
	@Override
	public boolean update(TbFirmManageEntity tbFirmManageEntity) {
		LambdaUpdateWrapper<TbFirmManageEntity> wrapper = Wrappers.<TbFirmManageEntity>lambdaUpdate();
		wrapper.eq(TbFirmManageEntity::getFirmId, tbFirmManageEntity.getFirmId());
		return this.update(tbFirmManageEntity, wrapper);
	}
}
